package com.lbj.googleplay.googleplay100.utils;

import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.StateListDrawable;

public class DrawableUtils {
    //获取形状
    public static GradientDrawable getGradientDrawable(int color,int radius){
        //xml中定义的shape标签对应此类
        GradientDrawable shape = new GradientDrawable();
        shape.setShape(GradientDrawable.RECTANGLE);//矩形
        shape.setCornerRadius(radius);//圆角半径
        shape.setColor(color);//颜色

        return shape;
    }

    //获取一个状态选择器
    public static StateListDrawable getSelector(Drawable normal, Drawable press ){
        StateListDrawable selector = new StateListDrawable();
        selector.addState(new int[]{android.R.attr.state_pressed},press);//按下图片
        selector.addState(new int[]{},normal);  //默认图片
        return selector;
    }

    //重载方法,获取一个状态选择器
    public static StateListDrawable getSelector(int normalColor, int pressColor,int radius){

        GradientDrawable bgormal = getGradientDrawable(normalColor, radius);
        GradientDrawable bgress = getGradientDrawable(pressColor, radius);
        StateListDrawable selector = getSelector(bgormal, bgress);
        return selector;
    }
}
